package com.yanqu.road.dao.impl.player;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.player.InternalUserIpLocation;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class InternalUserDaoImpl extends TempDao {

    public Map<Long, InternalUserIpLocation> getInternalUserIpLocation(long severId) throws Exception {
        ResultSet rs = null;
        CallableStatement call = null;
        String sql = "select * from t_s_internal_user where serverId = ?";
        Map<Long, InternalUserIpLocation> dataMap = new ConcurrentHashMap<>();
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(sql);
            call.setLong(1, severId);
            rs = call.executeQuery();
            while (rs.next()) {
                InternalUserIpLocation userIpLocation = new InternalUserIpLocation();
                userIpLocation.setUserId(rs.getLong("userId"));
                userIpLocation.setIpLocation(rs.getString("ipLocation"));
                dataMap.put(userIpLocation.getUserId(), userIpLocation);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
            throw e;
        } finally {
            getDb().closeConnection(call, rs);
        }
        return dataMap;
    }
}

